<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>平台管理</title>
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/easyui.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/icon.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/neweasyui/themes/gray/panel.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/style/neweasyui/themes/gray/window.css">
  <script type="text/javascript" src="<%=path %>/script/1.11.1.js"></script>
  <script type="text/javascript" src="<%=path %>/script/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="<%=path %>/script/easyui-lang-zh_CN.js"></script>
  <script type="text/javascript" src="<%=path %>/script/dateFormat.js"></script>
  <script type="text/javascript" src="<%=path %>/script/datagrid-bufferview.js"></script>
  <script type="text/javascript" src="<%=path %>/script/common.js"></script>
  <style type="text/css">
    #fm{
      margin:0;
      padding:10px 30px;
    }
    .ftitle{
      font-size:14px;
      font-weight:bold;
      padding:5px 0;
      margin-bottom:10px;
      border-bottom:1px solid #ccc;
    }
    .fitem{
      margin-bottom:17px;
    }
    .fitem label{
      display:inline-block;
      width:80px;
    }
    .fitem input{
      width:230px;
    }
  </style>
</head>
<body>
<table id="tt" title="平台管理" style="width:auto;height:500px">
</table>
<div id="toolbar" style="padding:5px;height:auto">
  <div>
    <!-- 搜索条件结束 -->
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-add" onclick="addPosition()">添加</a>&nbsp;
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-edit" onclick="editPosition()">修改</a>&nbsp;
    <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-remove" onclick="deletePosition()">删除</a>&nbsp;&nbsp; 
  </div>
</div>
<!--course 添加/编辑框 开始-->
<div id="add_edit_dialog" class="easyui-dialog"
     style="width: 500px; height: 350px; padding: 10px 20px" closed="true"
     buttons="#dlg-course-buttons">
  <div class="ftitle">位置 添加/编辑框</div>
  <form id="add_edit" method="post"  validate>
    <input type="hidden" name="id" id="id" />
    <div class="fitem">
      <label>guid:</label>
      <input  class="easyui-textbox" name="guid" id="guid" value="" required validType="length[0,32]"/>
    </div>
    <div class="fitem">
      <label>名称:</label>
      <input  class="easyui-textbox" name="name" id="name" value="" required/>
    </div>
  </form>
  <div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6"  iconCls="icon-ok" onclick="saveOrUpdatePosition()" style="width: 90px">Save</a> 
    <a href="javascript:void(0)" class="easyui-linkbutton"  iconCls="icon-cancel" onclick="closeDialog()" style="width: 90px">Cancel</a>
  </div>
</div>

</body>
<script type="text/javascript">
    
  $.ajaxSetup({cache:false});
  $(function(){
    $('#start_date').datetimebox({
      showSeconds:false,parser:w3

    });
    $('#end_date').datetimebox({
      showSeconds:false,parser:w3
    });
    $('#tt').datagrid({
      url:'<%=basePath %>service/ad/list/paddress',
      method:'get',
      singleSelect:true,toolbar:'#toolbar',remoteSort:false,pageSize:50,nowrap:false,
      fitColumns:true,
      rownumbers: true,
      pagination:true,
      columns:[[
        {field:'id',title:'ID',sortable:true,width:15,hidden:true},
        {field:'guid',title:'GUID',sortable:true,width:80},
        {field:'name',title:'名称',sortable:true,width:80}
      ]]
    });

  });
//显示dialog
  function addPosition(){
	  $('#add_edit_dialog').dialog('open').dialog('setTitle','添加平台');
	   $('#add_edit').form('clear');
     url = '<%=basePath%>service/ad/add/paddress';
  }
//添加或修改广告
  function saveOrUpdatePosition(){

    $('#add_edit').form('submit', {
      url : url,
      onSubmit : function() {
        return $(this).form('validate');
      },
      success : function(result) {

        if (result.status) {
          $.messager.show({
            title : 'Error',
            msg : '服务器出错，请稍后再试'
          });
        } else {
          $('#add_edit_dialog').dialog('close'); // close the dialog
          $('#tt').datagrid('reload'); // reload the data
        }
      }
    });
  }
  //显示dialog
  function editPosition(){
    url = '<%=basePath%>service/ad/edit/paddress';
    var row = $('#tt').datagrid('getSelected');
    if (row){
    	$("#id").val(row.id);
    	$("#guid").val(row.guid);
    	$("#name").val(row.name);
    	$('#add_edit_dialog').dialog('open').dialog('setTitle','修改平台');
    	$('#add_edit').form('load',row);
    }else {
    	alert("请选择要修改的位置");
    }
  }
  
  function deletePosition(){

    var row = $('#tt').datagrid('getSelected');
    if (row){
      $.messager.confirm('提示','确定要删除这个class吗？',function(r){
        if (r){
          $.post('<%=basePath%>service/ad/delete/paddress',{id:row.id},function(result){
            $('#tt').datagrid('reload');    // reload the data
          },'json');
        }
      });
    }else {
    	alert("请选择要删除的数据");
    }
  }
//关闭弹出框
  function closeDialog(){
    $('#add_edit_dialog').dialog('close') ;
  }

</script>
</html>
